package city.spring.modules.medicine.repository;

import city.spring.modules.medicine.entity.MedicinereceiptEntity;
import city.spring.modules.medicine.vo.MedicinereceiptVO;
import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

/**
 * 存储库：药品领用申请
 *
 * @author 谢金婷
 * @date 2020-06-27 11:27:59
 */
@Repository
public interface MedicinereceiptRepository extends BaseMapper<MedicinereceiptEntity> {
    /**
     * 根据id获取领用申请信息
     *
     * @param id
     * @return
     */
    MedicinereceiptEntity getMedicinereceiptById(@Param("id") String id);

    /**
     * 获取审核通过的领用申请信息
     *
     * @param page
     * @return
     */
    IPage<MedicinereceiptEntity> getMedicinereceiptPass(IPage<MedicinereceiptEntity> page, AbstractWrapper wrapper);

    /**
     * 获取非审核通过的领用申请信息
     *
     * @param page
     * @return
     */
    IPage<MedicinereceiptEntity> getMedicinereceiptNoPass(IPage<MedicinereceiptEntity> page, AbstractWrapper wrapper);

    IPage<MedicinereceiptVO> listPage(Page<? extends MedicinereceiptEntity> page, @Param(Constants.WRAPPER) Wrapper<? extends MedicinereceiptEntity> wrapper);

    IPage<MedicinereceiptVO> approvalListPage(Page<? extends MedicinereceiptEntity> page, @Param(Constants.WRAPPER) Wrapper<? extends MedicinereceiptEntity> wrapper);

    IPage<MedicinereceiptVO> deliveryListPage(Page<? extends MedicinereceiptEntity> page, @Param(Constants.WRAPPER) Wrapper<? extends MedicinereceiptEntity> wrapper);

    /**
     * 统计最大可领用数量
     * 现有库存-待出库数量（领用待审核数量）
     *
     * @param name
     * @param category
     * @param specifications
     * @param unit
     * @param dosageunit
     * @return
     */
    BigDecimal getOptionalQuantity(String name, String category, String specifications, String type, String unit, String dosageunit);
}